﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace projekt_1._0
{
    public partial class Megrendelok : Form
    {
        private SqlConnection cn;
        private MegrendelokDal MegrendelokPeldany;
        private int pointer;
        public Megrendelok()
        {
            InitializeComponent();
            MegrendelokPeldany = new MegrendelokDal();
        }

        private void Megrendelok_Load(object sender, EventArgs e)
        {
            try
            {

                cn = new SqlConnection();
                cn.ConnectionString = "server=ECNEBYGAN-PC;Database=abprojekt;uid=ecneBygaN-PC\\ecneBygaN;Integrated Security=true;";
                cn.Open();
                MegrendelokPeldany.DgwFill(MegrendelokDgw, MCegNevTb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a serverhez valo kapcsolodasnal!" + ex);
            }

        }

        private void FomenuG_Click(object sender, EventArgs e)
        {
            try
            {
                Fomenu Fomenu = new Fomenu();
                cn.Close();
                this.Visible = false;
                Fomenu.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a kapcsolat letrehozasanal" + ex);
            }
        }

        private void KilepG_Click(object sender, EventArgs e)
        {
            cn.Close();
            Application.Exit();
        }

        private void MCegNevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.DgwFill(MegrendelokDgw, MCegNevTb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a serverhez valo kapcsolodasnal!" + ex);
            }

        }

        private void MHelysegTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.DgwFillHelyseg(MegrendelokDgw, MHelysegTb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a serverhez valo kapcsolodasnal!" + ex);
            }

        }

 
        //Uj gomb lenyomasa eseten eltunnek bizonyos dolgok illetve megjelennek
        private void UjG_Click(object sender, EventArgs e)
        {
            CodFiscalL.Visible = true;
            CodFiscalTb.Visible = true;
            CuiL.Visible = true;
            CuiTb.Visible = true;
            CegNevL.Visible = true;
            CegNevTb.Visible = true;
            BankNevL.Visible = true;
            BankNevTb.Visible = true;
            BankSzamlaL.Visible = true;
            BankSzamlaTb.Visible = true;
            HelysegL.Visible = true;
            HelysegTb.Visible = true;
            CimL.Visible = true;
            CimTb.Visible = true;
            MegrendeloNevL.Visible = true;
            MegrendeloTb.Visible = true;
            BuletinSzamL.Visible = true;
            BuletinSzamTb.Visible = true;
            KapcsolatCb.Visible = true;
            KapcsolatL.Visible = true;
            UjG.Visible = false;
            UjL.Visible = false;
            ModositG.Visible = false;
            ModositL.Visible = false;
            TorlesG.Visible = false;
            TorlesL.Visible = false;
            MHelysegL.Visible = false;
            MHelysegTb.Visible = false;
            MCegNevL.Visible = false;
            MCegNevTb.Visible = false;
            FomenuG.Visible = false;
            KilepG.Visible = false;
            MentesG.Visible = true;
            MegseG.Visible = true;
            pointer = 1;

            try
            {
                MegrendelokPeldany.ComboFill(KapcsolatCb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba az adatok modositasanal!"+ex);
            }
            try
            {
                MegrendelokPeldany.BeallitCombo(KapcsolatCb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Nem sikerult a kapcsolattarto szemely beallitasa" + ex);
            } 
                  
        }

        private void ModositL_Click(object sender, EventArgs e)
        {

        }
        //A megse gomb lenyomasa eseteb bizonyos dolgok megjelennek illetve eltunnek
        private void MegseG_Click(object sender, EventArgs e)
        {
            CodFiscalL.Visible = false;
            CodFiscalTb.Visible = false;
            CuiL.Visible = false;
            CuiTb.Visible = false;
            CegNevL.Visible = false;
            CegNevTb.Visible = false;
            BankNevL.Visible = false;
            BankNevTb.Visible = false;
            BankSzamlaL.Visible = false;
            BankSzamlaTb.Visible = false;
            HelysegL.Visible = false;
            HelysegTb.Visible = false;
            CimL.Visible = false;
            CimTb.Visible = false;
            MegrendeloNevL.Visible = false;
            MegrendeloTb.Visible = false;
            BuletinSzamL.Visible = false;
            BuletinSzamTb.Visible = false;
            KapcsolatCb.Visible = false;
            KapcsolatL.Visible = false;
            MentesG.Visible = false;
            MegseG.Visible = false;
            UjG.Visible = true;
            UjL.Visible = true;
            ModositG.Visible = true;
            ModositL.Visible = true;
            TorlesG.Visible = true;
            TorlesL.Visible = true;
            MHelysegL.Visible = true;
            MHelysegTb.Visible = true;
            MCegNevL.Visible = true;
            MCegNevTb.Visible = true;
            FomenuG.Visible = true;
            KilepG.Visible = true;
            MentesG.Visible = false;
            MegseG.Visible = false;
        }
        //a cod fiscal inicializalsa a textbox alapjan
        private void CodFiscalTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitCodFiscal(CodFiscalTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Cod Fiscal a beallitasanal" + ex);
            }
        }
        // a cui inicializala a textbox alapjan
        private void CuiTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitCui(CuiTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Cui beallitasanal" + ex);
            }
        }
        //A Cegnev beallitasa a textbox alapjan
        private void CegNevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitCegNev(CegNevTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Cegnev beallitasanal" + ex);
            }
        }
        //A banknev inicializalasa
        private void BankNevTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitBankNev(BankNevTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Banknev beallitasanal" + ex);
            }

        }
        //a bankszamlaszam beallitasa
        private void BankSzamlaTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitBankSzamlaSzam(BankSzamlaTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a bankszamla szam beallitasanal" + ex);
            }
        }
        //inicializalom a helyseget a textbox alapjan
        private void HelysegTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitHelyseg(HelysegTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a Helyseg beallitasanal" + ex);
            }

        }
        //beallitom a cimet a textbox alapjan
        private void CimTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BealliCim(CimTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a cim beallitasanal" + ex);
            }
        }
        //a megrendelo nevenek az inicializalasa
        private void MegrendeloTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitMegrendelonev(MegrendeloTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a megrendelo nevenek a beallitasanal" + ex);
            }
        }

        private void BuletinSzamTb_TextChanged(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.BeallitBuletinSzam(BuletinSzamTb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba a buletinszam beallitasanal" + ex);
            }
        }
        //a como alapjan beallitom a sajat valtozomat
        private void KapcsolatCb_SelectedIndexChanged(object sender, EventArgs e)
        {
              try
              {
                MegrendelokPeldany.BeallitCombo(KapcsolatCb);
              }
             catch (Exception ex)
              {
                MessageBox.Show("Nem sikerult a kapcsolattarto szemely beallitasa" + ex);
              } 
        }

        private void MentesG_Click(object sender, EventArgs e)
        {
            if (pointer == 1)
            {
              
                try
                {
                    if (MegrendelokPeldany.Mentes(cn) == true)
                    {
                        CodFiscalL.Visible = false;
                        CodFiscalTb.Visible = false;
                        CuiL.Visible = false;
                        CuiTb.Visible = false;
                        CegNevL.Visible = false;
                        CegNevTb.Visible = false;
                        BankNevL.Visible = false;
                        BankNevTb.Visible = false;
                        BankSzamlaL.Visible = false;
                        BankSzamlaTb.Visible = false;
                        HelysegL.Visible = false;
                        HelysegTb.Visible = false;
                        CimL.Visible = false;
                        CimTb.Visible = false;
                        MegrendeloNevL.Visible = false;
                        MegrendeloTb.Visible = false;
                        BuletinSzamL.Visible = false;
                        BuletinSzamTb.Visible = false;
                        KapcsolatCb.Visible = false;
                        KapcsolatL.Visible = false;
                        MentesG.Visible = false;
                        MegseG.Visible = false;
                        UjG.Visible = true;
                        UjL.Visible = true;
                        ModositG.Visible = true;
                        ModositL.Visible = true;
                        TorlesG.Visible = true;
                        TorlesL.Visible = true;
                        MHelysegL.Visible = true;
                        MHelysegTb.Visible = true;
                        MCegNevL.Visible = true;
                        MCegNevTb.Visible = true;
                        FomenuG.Visible = true;
                        KilepG.Visible = true;
                        MentesG.Visible = false;
                        MegseG.Visible = false;
                        pointer = 0;
                        MegrendelokPeldany.DgwFill(MegrendelokDgw, MCegNevTb, cn);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Hiba az uj megrendelo beszurasanal" + ex);
                }
            }
            if (pointer == 2)
            {
                
                 try
                {
                    if (MegrendelokPeldany.MentesModositasUtan(cn) == true)
                    {
                        CodFiscalL.Visible = false;
                        CodFiscalTb.Visible = false;
                        CuiL.Visible = false;
                        CuiTb.Visible = false;
                        CegNevL.Visible = false;
                        CegNevTb.Visible = false;
                        BankNevL.Visible = false;
                        BankNevTb.Visible = false;
                        BankSzamlaL.Visible = false;
                        BankSzamlaTb.Visible = false;
                        HelysegL.Visible = false;
                        HelysegTb.Visible = false;
                        CimL.Visible = false;
                        CimTb.Visible = false;
                        MegrendeloNevL.Visible = false;
                        MegrendeloTb.Visible = false;
                        BuletinSzamL.Visible = false;
                        BuletinSzamTb.Visible = false;
                        KapcsolatCb.Visible = false;
                        KapcsolatL.Visible = false;
                        MentesG.Visible = false;
                        MegseG.Visible = false;
                        UjG.Visible = true;
                        UjL.Visible = true;
                        ModositG.Visible = true;
                        ModositL.Visible = true;
                        TorlesG.Visible = true;
                        TorlesL.Visible = true;
                        MHelysegL.Visible = true;
                        MHelysegTb.Visible = true;
                        MCegNevL.Visible = true;
                        MCegNevTb.Visible = true;
                        FomenuG.Visible = true;
                        KilepG.Visible = true;
                        MentesG.Visible = false;
                        MegseG.Visible = false;
                        pointer = 0;
                        MegrendelokPeldany.DgwFill(MegrendelokDgw, MCegNevTb, cn);
                    }
                }
                
                catch (Exception ex)
                {
                    MessageBox.Show("Hiba az uj megrendelo modositasanal" + ex);
                }
            }
                       
        }

        private void ModositG_Click(object sender, EventArgs e)
        {
            //CodFiscalL.Visible = true;
            //CodFiscalTb.Visible = true;
            CuiL.Visible = true;
            CuiTb.Visible = true;
            CegNevL.Visible = true;
            CegNevTb.Visible = true;
            BankNevL.Visible = true;
            BankNevTb.Visible = true;
            BankSzamlaL.Visible = true;
            BankSzamlaTb.Visible = true;
            HelysegL.Visible = true;
            HelysegTb.Visible = true;
            CimL.Visible = true;
            CimTb.Visible = true;
            MegrendeloNevL.Visible = true;
            MegrendeloTb.Visible = true;
            BuletinSzamL.Visible = true;
            BuletinSzamTb.Visible = true;
            KapcsolatCb.Visible = true;
            KapcsolatL.Visible = true;
            UjG.Visible = false;
            UjL.Visible = false;
            ModositG.Visible = false;
            ModositL.Visible = false;
            TorlesG.Visible = false;
            TorlesL.Visible = false;
            MHelysegL.Visible = false;
            MHelysegTb.Visible = false;
            MCegNevL.Visible = false;
            MCegNevTb.Visible = false;
            FomenuG.Visible = false;
            KilepG.Visible = false;
            MentesG.Visible = true;
            MegseG.Visible = true;
            pointer = 2;
            try
            {
                MegrendelokPeldany.ComboFill(KapcsolatCb, cn);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba az adatok modositasanal!" + ex);
            }
            try
            {
                MegrendelokPeldany.BeallitCombo(KapcsolatCb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Nem sikerult a kapcsolattarto szemely beallitasa" + ex);
            }
            try
            {
                MegrendelokPeldany.BeallitModositashoz(MegrendelokDgw, CodFiscalTb, CuiTb, CegNevTb, BankNevTb, BankSzamlaTb, HelysegTb, CimTb, MegrendeloTb, BuletinSzamTb, KapcsolatCb);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba az adatok betoltese kozben" + ex);

            }
      
        }

        private void TorlesG_Click(object sender, EventArgs e)
        {
            try
            {
                MegrendelokPeldany.Torol(MegrendelokDgw, cn);
                MegrendelokPeldany.DgwFill(MegrendelokDgw, MCegNevTb, cn); 
            }
            catch (Exception ex)
            {
                MessageBox.Show("Hiba torles kozben");
            }

        }

    

    }
}
